package com.zdsoft.blp.gongyong.camera;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zdsoft.blp.R;

import java.io.File;

/**
 * Created by pc on 2016/9/3.
 */
public class Camera {
    public static final int PAI = 1;
    public static final int XUAN = 2;
    public static AlertDialog dialog;

    public static void setOnClickListener(ImageView iv, final Context context) {

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_zhaoxiang, null);
        builder.setView(dialogView);

        TextView tv_xuanze = (TextView) dialogView.findViewById(R.id.tv_xuanze);
        TextView tv_paizhao = (TextView) dialogView.findViewById(R.id.tv_paizhao);
        tv_xuanze.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                intent.setType("image/*");
                ((Activity) context).startActivityForResult(intent, XUAN);
            }
        });

        tv_paizhao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentFromCapture = new Intent(
                        MediaStore.ACTION_IMAGE_CAPTURE);
                // 判断存储卡是否可以用，可用进行存储
                if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                    intentFromCapture.putExtra(MediaStore.EXTRA_OUTPUT,
                            Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "image.jpg")));
                }
                ((Activity) context).startActivityForResult(intentFromCapture, PAI);
            }
        });

        builder.create();
        dialog = builder.show();


    }


}
